<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="5" :sm="8">
            <a-form-item label="用途">
              <a-input placeholder="请输入用途" v-model="queryParam.purpose" @pressEnter="searchQuery"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="8">
            <a-form-item label="节点名称">
              <a-input placeholder="请输入节点名称" v-model="queryParam.processNodeName" @pressEnter="searchQuery"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="8">
            <span style="float: left;overflow: hidden;margin-top: 5px;" class="table-page-search-submitButtons">
              <a-button type="primary" size="small" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" size="small" @click="searchReset" icon="reload"
                        style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" size="small" icon="plus" v-has="'ActCandidateConfigList:add'">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('审批流候选人配置')"
                v-has="'ActCandidateConfigList:exportXls'" size='small'>导出
      </a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
                @change="handleImportExcel">
        <a-button type="primary" icon="import" v-has="'ActCandidateConfigList:importXls'" size='small'>导入</a-button>
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0" v-has="'ActCandidateConfigList:deleteBatch'">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px" size='small'> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <!-- <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div> -->

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">
        <div slot="filterDropdown">
                    
          <a-card>
            <a-checkbox-group @change="onColSettingsChange"  v-model="settingColumns"  :defaultValue="settingColumns">
              <a-row>
                <template v-for="item in defColumns">
                  <template v-if="item.key != 'rowIndex' && item.dataIndex != 'action'">
                    <a-col :span="6"  :key="item.key">
                      <a-checkbox :value="item.dataIndex">
                        {{ item.title }}
                      </a-checkbox>
                    </a-col>
                  </template>
                </template>
              </a-row>
            </a-checkbox-group>
          </a-card>
        </div>
                
        <a-icon slot="filterIcon"  type="setting"  :style="{ fontSize: '16px', color: '#fff' }"  />

        <template slot="fieldConditionResultsText" slot-scope="text,record">
          <j-ellipsis v-if="text" :value="text" :length="15"></j-ellipsis>
          <j-ellipsis v-else :value="record.fieldConditionResults" :length="15"></j-ellipsis>
        </template>
        <template slot="candidateResultsText" slot-scope="text,record">
          <j-ellipsis v-if="text" :value="text" :length="15"></j-ellipsis>
          <j-ellipsis v-else :value="record.candidateResults" :length="15"></j-ellipsis>
        </template>
        <template slot="fieldConditionCategory" slot-scope="text">
          <span v-if="text=='depart'">部门</span>
          <span v-if="text==='role'">角色</span>
          <span v-if="text==='user'">用户</span>
          <span v-if="text==='function'">自定义方法</span>
          <span v-if="text==='variable'">常量</span>
        </template>
        <template slot="candidateCategory" slot-scope="text">
          <span v-if="text==='role'">角色</span>
          <span v-if="text==='user'">用户</span>
          <span v-if="text==='function'">自定义方法</span>
        </template>
        <template slot="status" slot-scope="text">
          <a-tag v-if="text==0" color="red">停止</a-tag>
          <a-tag v-if="text==1" color="blue">启用</a-tag>
        </template>
        <span slot="action" slot-scope="text, record" class="publicFlex">
          <a @click="handleEdit(record)" v-has="'ActCandidateConfigList:edit'">编辑</a>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item  v-has="'ActCandidateConfigList:delete'">
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
               <a-menu-item>
               <a @click="generatingExpression(record)">生成表达式</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <actCandidateConfig-modal ref="modalForm" @ok="modalFormOk"></actCandidateConfig-modal>
    <generating-expression ref="expression"></generating-expression>
  </a-card>
</template>

<script>

  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import ActCandidateConfigModal from './modules/ActCandidateConfigModal'
  import JEllipsis from "@/components/jeecg/JEllipsis";
  import generatingExpression from './modules/GeneratingExpression'

  export default {
    name: "ActCandidateConfigList",
    mixins: [JeecgListMixin],
    components: {
      JEllipsis,
      ActCandidateConfigModal,
      generatingExpression
    },
    data() {
      return {
        description: '审批流候选人配置管理页面',
        // 表头
        settingColumns: [],
        columns: [],
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '用途',
            align: "center",
            dataIndex: 'purpose'
          },
          {
            title: '表名',
            align: "center",
            dataIndex: 'tableName'
          },
          {
            title: '字段',
            align: "center",
            dataIndex: 'fieldName',

          },
          {
            title: '字段描述',
            align: "center",
            dataIndex: 'fieldDescription'
          },
          {
            title: '字段条件',
            align: "center",
            dataIndex: 'fieldCondition'
          },
          {
            title: '字段条件类别',
            align: "center",
            dataIndex: 'fieldConditionCategory',
            scopedSlots:{customRender:'fieldConditionCategory'}
          },
          {
            title: '字段条件结果',
            align: "center",
            dataIndex: 'fieldConditionResultsText',
            scopedSlots:{customRender:'fieldConditionResultsText'}
          },
          {
            title: '候选类别',
            align: "center",
            dataIndex: 'candidateCategory',
            scopedSlots:{customRender:'candidateCategory'}
          },
          {
            title: '候选结果',
            align: "center",
            dataIndex: 'candidateResultsText',
            scopedSlots:{customRender:'candidateResultsText'}
          },{
            title: '节点名称',
            align: "center",
            dataIndex: 'processNodeName'
          },
          {
            title: '状态',
            align: "center",
            dataIndex: 'status',
            scopedSlots:{customRender:'status'}
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            scopedSlots: {
              filterDropdown: 'filterDropdown', // 新增筛选插槽
              filterIcon: 'filterIcon', // 新增图标插槽
              customRender: 'action' // 原操作列插槽
            }
          }
        ],
        url: {
          list: "/actcandidateconfig/actCandidateConfig/list",
          delete: "/actcandidateconfig/actCandidateConfig/delete",
          deleteBatch: "/actcandidateconfig/actCandidateConfig/deleteBatch",
          exportXlsUrl: "/actcandidateconfig/actCandidateConfig/exportXls",
          importExcelUrl: "actcandidateconfig/actCandidateConfig/importExcel"
        },
        dictOptions: {}

      }
    },
    computed: {
      importExcelUrl: function () {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      initDictConfig() {
      },
      generatingExpression(record){
        this.$refs.expression.open(record)
      }

    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>